Tester - Unit Testing for Php

Unit testing library.

UNDER DEVELOPMENT: v0.3 is pretty functional, but this v1.0 is under development and not ready to use.

Documentation

Getting Started

Use defaults, or Configure as needed.

Follow steps below, or see an example.

Create a test

  1. vendor/bin/phptest create-test
  2. Follow the prompts, which will create a new test file
  3. Setup your test in the testMain() method (or create new testWhatever() methods)

A test is a single method within a class implementing the Tlf\Tester interface, prefixed with test. Alternatively, use $tester->add_test($callable) in your test/bootstrap.php file.

For a test to pass, all assertions in the test must pass. If any assertions fail, or if there are no assertions, then the test fails.

Tips

  • Most accessible methods on $this are assertions.
  • $this has multiple helper objects as properties. Try db, server, exceptions, and utility

Run your tests

  • vendor/bin/phptest: Run all tests
  • vendor/bin/phptest -test TestName: Run tests with the given TestName (Supports multiple -test flags)
  • vendor/bin/phptest -class ClassBaseName: Run all tests for a class. (Supports multiple -class flags)

Screenshots & Examples

Also see the CLI documentation.

CLI Help Menu

... include image here ...

Test Results

... test results ...

Example Test class

<?php  
  
namespace Tlf\Tester\Test\Runner;  
  
class NestedTest extends \Tlf\Tester {  
  
    /** called before tests are run */  
    public function prepare(){}  
  
    /** Test methods must prefix with `test` */  
    public function testAnything(){  
        $this->compare(true,true);  
    }  
}